<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="uct" uri="/WEB-INF/uct.tld" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <%@ include file="/common/sale/include/common-base.jsp"%>	
  <title>IUS|数据代码集-${titleName }</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

</head>
<body class="hold-transition skin-yellow sidebar-mini">
<div class="wrapper">
  <!-- top start -->
  <%@include file="/common/sale/top.jsp" %>
  <!-- top end -->
  <!-- left start -->
  <%@include file="/common/sale/left.jsp" %>
  <!-- left end-->

  <div class="content-wrapper">
  <!-- 
  		<br/>
		<ol class="breadcrumb bgblue">
			<li>
				<span class="label label-danger font14" >系统管理 /数据字典管理</span>
			</li>
		</ol>
	 -->	
    <!-- Main start -->

<section class="content">
      <div class="row">
        <div class="col-xs-12">
          <div class="box box-info">
            <div class="box-header">
               <h3 class="box-title"><i class="fa fa-user"></i> 数字字典类型
                 　　　                  <button class="btn btn-success" type="button" onclick="toAdd('parent');">增加</button>
				   <button class="btn btn-info" type="button" onclick="del();">删除</button>
			  	   <button class="btn btn-info" type="button" onclick="toEdit();">修改</button>
				   <button class="btn btn-warning" type="button" onclick="refresh();">刷新</button>
                 </h3>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
            
            <center>
				<form id="searchFrom" class="form-horizontal">
				<input type="hidden" name="doCode" value="dictCateList"/>
				<input type="hidden" name="sysEname" value="default"/>
				科目名称：<input type="text" class="form-control" style="height: 30px; display: inline; width: 13%;"  name="cateCname" id="cateCname" value="" />
				科目标识: <input type="text" class="form-control" style="height: 30px; display: inline; width: 13%;"  name="cateEname" id="cateEname" value="" />
							
				<button type="button" class="btn btn-primary" onclick="getTableData();">查询</button>
				<button  type="button" class="btn btn-primary" onclick="cleanData('searchFrom');">重置 </button>
				</form>
				</center>
            
              <table id="example" class="table table-bordered " >
                <thead>
                <tr>
              	  <th>科目名称</th>
                  <th>科目标识</th>
                  <th>状态</th>
                  <th>描述</th>
                  <th>操作</th>
                </tr>
                </thead>
                <tbody id="myList">
                </tbody>
              </table>
                <center>
    	  			  <ul id="pageList"></ul>
        		</center>
            </div>
          </div>
        </div>
      </div>
    </section>
    <!-- Main end -->
  </div>
  <!-- /.content-wrapper -->
  <!-- foot start -->
       
  <%@include file="/common/sale/foot.jsp" %>
  <!-- foot start -->
  <div class="modal fade" id="my_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						<h4 class="modal-title"><font color="red">科目信息</font>&nbsp;</h4>
					</div>
					<div class="modal-body">
						<form class="form-horizontal" role="form" id="orgForm">
							<input type="hidden" name="formToken" id="formToken" value="${formToken}"/>
							<input type="hidden" name="cateId" id="cateId" value="${item.cateId}"/>
							<input type="hidden" name="oldCateEname" id="oldCateEname" value="${item.cateEname}"/>
							<input type="hidden" name="sysEname" value="${sysName }"/>
						    <input type="hidden" name="doCode" value="dictCateSave"/>
							 <div class="box-body" id="orgFormData">
			                <div class="form-group">
			                  <label  class="col-sm-4 control-label" >科目中文名称</label>
			                  <div class="col-sm-6">
			                    <input type="text" class="form-control" id="cateCname"  name="cateCname" required placeholder="必填项">
			                  </div>
			                </div>
			                
			                <div class="form-group">
			                  <label class="col-sm-4 control-label">科目标识</label>
			                  <div class="col-sm-6">
			                    <input type="text" class="form-control" id="cateEname" name="cateEname" required placeholder="必填项">
			                  </div>
			                </div>
			                
			                <div class="form-group">
			                  <label class="col-sm-4 control-label">描述</label>
			                  <div class="col-sm-6">
			                    <input type="text" class="form-control" id="cateRemark" name="cateRemark" placeholder="">
			                  </div>
			                </div>
			                
			                <div class="form-group">
			                  <label class="col-sm-4 control-label">状态</label>
			                  <div class="col-sm-6">
			                    <input type="radio" checked="checked" value="1" name="cateStatus"> <i></i> 启用 
                                <input type="radio" value="0" name="cateStatus"> <i></i> 停用
			                  </div>
			                </div>
			                
			              </div>
			               <div class="box-footer">
			                <button type="button" class="btn btn-primary pull-left" onclick="cannel();">取消</button>
			                <button type="button" class="btn btn-primary pull-right" onclick="save('orgForm');">提 交</button>
			              </div>
						</form>
					</div>
				</div>
				<!-- /.modal-content -->
			</div>		
</div>  

<div class="modal fade" id="my_modal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width:1020px;height:500px;">
	   <div class="modal-content" id="dataItemManager" style="height:500px;"></div>
	</div>
</div> 
  
</body>
	<script type="text/template" id="dataList">
	  		<? for ( var i = 0; i < rows.length; i++) {?>
				<tr id=<?=rows[i].cateId?> >
					<th style="display:none;"><?=rows[i].cateId?></th>
					<td><?=rows[i].cateCname?></td>
					<td><?=rows[i].cateEname?></td>
					<td><?if("1"==rows[i].cateStatus){?><font color=blue>启用</font>
                        <?}else{?><font color=red>停用</font><?}?>
                    </td>
					<td><?=rows[i].cateRemark?></td>
                    <td><a href="javascript:void('0');" onclick="itemTrees('<?=rows[i].cateEname?>','<?=rows[i].cateCname?>')">条目管理</a></td>
				</tr>
     		<?}?>
	</script>


<script>
var clickMenu= 'sys-dict-list';
var id;
var cateEname;
$(function () {
	getTableData();
	$('#example tbody').on('click','tr', function (e) {
	     if ( $(this).hasClass('selected') ) {
	            //$(this).removeClass('selected');
	        }  else {
	            $('tr.selected').removeClass('selected');
	            $(this).addClass('selected');
	        }
	     id = $('tr.selected th').eq(0).html();
	     cateEname = $('tr.selected td').eq(1).html();
	   //  console.log($('tr.selected td').eq(1).html())
	} );
  });
  
//设置模态框隐藏事件钩子  
$( '#my_modal' ).on( 'hide.bs.modal' ,function(e){  
	cleanData('orgFormData');
}); 

//设置模态框隐藏事件钩子  
$( '#my_modal' ).on( 'show.bs.modal' ,function(e){  
	$.ajax({ type:'post',url:'${ctx}/sendPage/token?token=true', dataType:'json',
	    success: function(myData){
	    	//console.log(myData);
		  $('#formToken').val(myData);
	  	}
	});	
}); 
  
function cleanData(id){
	$(':input','#'+id)  
	 .not(':button, :submit, :reset, :hidden,:radio')  
	 .val('')  
	 //.removeAttr('checked')  
	 .removeAttr('selected'); 
}


function getTableData(){
	$.ajax({url:common_list_url,type: "get",dataType: "json",
			data:$('#searchFrom').serialize()+getCurrentPage(dictUrl+"?"+$('#searchFrom').serialize(),8),
	        error: function(){   alert('异常错误'); },  
		   success: function(myData){
			var data = baidu.template('dataList',myData);  
			$("#myList").html(data);
			  var option= {ele:$("#pageList")[0],total:myData.total,fn:getTableData,
					   url:dictUrl+"?"+$('#searchFrom').serialize()}
			generatePages(option);
		   }
		});	
  }
  
  
function toAdd(){
	$('#my_modal').modal('show');
	setToken();
}

function itemTrees(code,cname){
	$("#dataItemManager").load("${ctx}/template/uct/dict-detail.html",function(){loadItems(code,cname);});
	$('#my_modal2').modal('show');
}

function toEdit(){
	if(id=="undefined" || id =="" || id == null){
		layer.alert('请先选中一条数据！', {
		    skin: 'layui-layer-molv'
		    ,closeBtn: 0
		  });
		return;
	}else{
		$.ajax({type:'get', url:common_info_url, dataType:'json',
		    data:{'cateId':id,'doCode':'dictCateInfo'},
		    success: function(myData){
		    	 //console.log(myData);
				 FormUtil.fillData("#orgForm", myData,"id");
				 DictUtil.checkRadioDict("cateStatus", myData.cateStatus);
				 $('#my_modal').modal('show');
				 setToken();
		  	}
		});	
	}
	//$('#my_modal').modal('show');
}

function del(){
	if(id=="undefined" || id =="" || id == null){
		layer.alert('请先选中一条数据！', {skin: 'layui-layer-molv' ,closeBtn: 0 });
		return;
	}else{
		layer.confirm('您确认要进行删除操作？', { btn: ['确认','取消'] }, 
		   function(){
				$.ajax({type:'post', url:common_submit_url, dataType:'json',
				    data:{'cateId':id,'doCode':'dictCateDel'},
				    success: function(myData){
				    	if(myData.flag=='T'){
				    		layer.alert('操作成功！', {skin: 'layui-layer-molv',closeBtn: 0 });
				    		id = "";
				    		refresh();
				    	}
				  	}
				});	
			}, 
		   function(){}
		);
	}
}
function save(formId){
	if(!$("#" + formId)[0].checkValidity()){
		alert("请先完善必输项和必选项！");
		return ;
	}
	$.ajax({ type:'post',url:common_submit_url,dataType:'json',
	    data:$("#"+formId).serialize(),
	    success: function(myData){
	    	//console.log(myData);
	    	if(myData.flag=='T'){
	    		layer.alert('操作成功！', {skin:'layui-layer-molv',closeBtn:0});
	    		$('#my_modal').modal('hide');
	    		refresh();
	    	}else{
	    		alert(myData.msg);
	    	}
	  	}
	});	
}

function cannel(){
	$('#my_modal').modal('hide');

}
function deleteAllRow(){
	var tb = document.getElementById('example');
	if(tb){
	     var rowNum=tb.rows.length;
	     for (i=1;i<rowNum;i++){
	         tb.deleteRow(i);
	         rowNum=rowNum-1;
	         i=i-1;
	     }
     }
}

function refresh(){
    //window.location.reload();
	getTableData();
}
function setToken(){
	$.ajax({ type:'get',url:'${ctx}/sendPage/token?token=true',dataType:'text',
	    success: function(myData){
		   $('#formToken').val(myData);
	  	}
	});	
}
</script>
</html>
